<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.solution.common.config.PublicConfig" %>
<%@ page import="com.solution.wx.common.constants.PublicConstants" %>
<%
	String basePath = PublicConfig.ROOT_PATH;
	String imgRootURL = PublicConfig.IMG_ROOT_URL; //阿里云图片显示域名
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>编辑收货地址</title>

<link rel="stylesheet" type="text/css" href="<%=basePath%>/statics_wx/css/style.css">
<script src="<%=basePath%>/statics_wx/js/jquery.min.js"></script>
<%-- 
<link rel="stylesheet" type="text/css" href="<%=basePath%>/statics_wx/css/weui.min.css">
<link rel="stylesheet" type="text/css" href="<%=basePath%>/statics_wx/css/jquery-weui.css">
<script src="<%=basePath%>/statics_wx/js/jquery-2.1.4.js"></script>
<script src="<%=basePath%>/statics_wx/js/jquery-weui.js"></script>
<script src="<%=basePath%>/statics_wx/js/area-picker.js"></script> 
--%>
<script src="<%=basePath%>/statics_wx/js/js.js"></script>

<!-- 引入jstl标签库 -->
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!-- root -->
<script type="text/javascript">
//系统域名 
var rootPath = '<%=basePath %>';
// 系统上传文件展示域名
var imgRootURL = '<%=imgRootURL %>';
</script>
<c:set var="rootPath" value="<%=basePath %>"></c:set>
<c:set var="imgRootURL" value="<%=imgRootURL %>"></c:set>

<script type="text/javascript" src="<%=basePath%>/statics/plugins/layer/layer.js"></script>
<script>
	$(function() {
		$('.view_defaultaddress dl dt b').click(function() {
			$(this).toggleClass('current');
			if($(".view_defaultaddress dl dt b").hasClass("current")) {
				$("#isDefault").val(1);
			} else {
				$("#isDefault").val(0);
			}
		});
	});
</script>
<style type="text/css">
* {
	/*font-size: 14px !important;*/
}
</style>
</head>
<body style="background: #f5f5f5">
	<form action="<%=basePath%>/wx/address/saveAddress" method="post" onsubmit="return doCheckAddress();">
		<div class="edit_address">
			<div class="edit_form">
				<dl>
					<dt>
						<strong>收货人</strong>
						<p>
							<input type="text" name="receiverName"  id="receiverName" value="${address.receiverName }" class="inputstyle1" placeholder="请输入您的姓名">
						</p>
					</dt>
					<dt>
						<strong>联系电话</strong>
						<p>
							<input type="text" name="mobile" id="mobile" value="${address.mobile }" class="inputstyle1" placeholder="请输入您的联系方式">
						</p>
					</dt>
					<dt>
						<strong>所在地区</strong>
						<p>
							<input class="inputstyle1" name="city" id="city" value="${address.provinceName } ${address.cityName } ${address.areaName } ${address.streetName }" type="text" placeholder="请选择地区"><i></i>
						</p>
					</dt>
					<dt>
						<strong>详细地址</strong>
						<p>
							<input type="text" name="address" id="address" value="${address.address }" class="inputstyle1" placeholder="请输入您的详细地址">
						</p> 
					</dt>
				</dl>
			</div>
		</div>
		<div class="view_defaultaddress">
			<dl>
				<dt>
					<strong>设为默认</strong>
					<p>
						<b <c:if test="${address.isDefault == 1 }"> class="current" </c:if>  ></b>
					</p>
				</dt>
			</dl>
		</div>
		<c:if test="${not empty address.id }">
			<div class="del_part">
				<p>
					<a href="javascript: doDelAddress('${address.id }');">删除地址</a>
				</p>
			</div>
		</c:if>
		<div class="login_other1">
			<p>
				<input type="submit" class="inputbtn1" value="保 存" />
			</p>
		</div>
		
		<input name="id" id="id" type="hidden" value="${address.id }">
		<input name="shoppingIds" id="shopping_ids" type="hidden" value="${shoppingIds }">
		<input name="areaCodes" id="areaCodes" value="${title }" type="hidden">
		<input name="isDefault" id="isDefault" type="hidden" value="${address.isDefault }">
		<!-- 选择区域所需隐藏域 -->
		<input type="hidden" id="provinceCode" name="provinceCode" value="${address.provinceCode }" />
		<input type="hidden" id="provinceName" name="provinceName" value="${address.provinceName }" />
		<input type="hidden" id="cityCode" name="cityCode" value="${address.cityCode }" />
		<input type="hidden" id="cityName" name="cityName" value="${address.cityName }" />
		<input type="hidden" id="areaCode" name="areaCode" value="${address.areaCode }" />
		<input type="hidden" id="areaName" name="areaName" value="${address.areaName }" />
		<input type="hidden" id="streetCode" name="streetCode" value="${address.streetCode }" />
		<input type="hidden" id="streetName" name="streetName" value="${address.streetName }" />
		
	</form>

<jsp:include page="area_helper.jsp" />

<script type="text/javascript">
/*
var $cityPicker = $('#city');
var provinceId = null;
var cityId = null;
var areaId = null;
var streetId = null;
if ($("#city").val()) {
	var newStrArea = $("#city").val().split(" ");
	var newStrCode = $("#city").attr('title').split(" ");
	provinceId = newStrCode[0];
	cityId = newStrCode[1];
	areaId = newStrCode[2];
	streetId = newStrCode[3];
	
	$cityPicker.val(newStrArea[0] + ' ' + newStrArea[1] + ' ' + newStrArea[2] + ' ' + newStrArea[3]);
}
$("#city").cityPicker({
	title : "请选择地址",
	provinceId : provinceId,
	cityId : cityId,
	areaId : areaId,
	streetId : streetId
});
*/
/**
 * 删除地址
 */
function doDelAddress(addressId) {
	//信息框-例2
	layer.msg('您确认要删除吗？', {
		time : 0 //不自动关闭
		,
		btn : [ '确认', '取消' ],
		yes : function(index) {
			window.location.href = rootPath + '/wx/address/doDelAddress?addressId=' + addressId;
		}
	});
}
/**
 * 校验地址表单
 */
function doCheckAddress() {
	var receiverName = $("#receiverName").val();
	if (!receiverName) {
		layer.msg('请输入收货人姓名', {
			time : 2000
		});
		return false;
	}
	/*
	if (!(/^[\u4e00-\u9fa5]+$/.test(receiverName))) {
		layer.msg('姓名必须为中文', {
			icon : 2,
			time : 2000
		});
		return false;
	}
	*/
	var mobile = $("#mobile").val();
	if (!mobile) {
		layer.msg('请输入您的联系电话', {
			time : 2000
		});
		return false;
	}
	// 1、是不是手机号
	if(!(/^1\d{10}$/.test(mobile))) {
		//不是手机号
		// 2、 验证是不是固话
		if(!(/^(\d{3,4}-?)?\d{7,9}$/g.test(mobile))) {
			layer.msg('请输入正确的联系电话', {
				time : 2000
			});
			return false;
		} 
	}
	/* if (!(/^1\d{10}$/.test(mobile) || (/^(\d{3,4}-?)?\d{7,9}$/g.test(mobile)))) {
		layer.msg('请输入正确的联系方式', {
			icon : 2,
			time : 2000
		});
		return false;
	} */
	var provinceCode = $("#provinceCode").val();
	var cityCode = $("#cityCode").val();
	var areaCode = $("#areaCode").val();
	var streetCode = $("#streetCode").val();
	var provinceName = $("#provinceName").val();
	var cityName = $("#cityName").val();
	var areaName = $("#areaName").val();
	var streetName = $("#streetName").val();
	if (!provinceCode || !cityCode || !areaCode || !streetCode || !provinceName || !cityName || !areaName
			|| !streetName) {
		layer.msg('请重新选择所在地区（省/市/区/街道）', {
			time : 2000
		});
		return false;
	}
	if (!$("#address").val()) {
		layer.msg('请输入您的详细地址', {
			time : 2000
		});
		return false;
	}
	return true;
}
</script>
</body>
</html>